// index.ts
// 获取应用实例
const app = getApp<IAppOption>();
const innerAudioContext = wx.createInnerAudioContext();
innerAudioContext.src = "https://public.img.china1.fun/muyu/muyu.mp3";
let timer: any;
Page({
  data: {
    count: 0,
    isPause: true,
    content: "功德+1",
    offset: {},
    showCenterrDialog: false,
  },
  // 事件处理函数
  handleClick(e: any) {
    if (timer) {
      return;
    }
    const x = e.detail.x;
    this.setData(
      {
        count: ++this.data.count,
        isPause: false,
        offset: { left: x },
      },
      () => {
        wx.setStorageSync("muyu-count", this.data.count);
        innerAudioContext.stop();
        innerAudioContext.play();
        timer = setTimeout(() => {
          this.setData({ isPause: true }, () => {
            clearTimeout(timer);
            timer = null;
          });
        }, 500);
      }
    );
  },

  //中间弹框点击事件
  onClickDialogCenter: function () {
    this.setData({
      showCenterrDialog: !this.data.showCenterrDialog
    })
  },

  formSubmit(e: any) {
    const content = e.detail.value.input
    if (content != "") {
      this.setData({ content })
      wx.setStorageSync("muyu-content", this.data.content);
      wx.showToast({
        title: '设置成功',
        icon: 'none',
        duration: 2000
      })
    }
    this.onClickDialogCenter()
  },
  onShareAppMessage() {
    return {
      title: "电子木鱼", // 分享出的卡片标题
      path: "pages/index/index", // 他人通过卡片进入小程序的路径，可以在后面拼接
      imageUrl: "../../assets/images/share.png",
    };
  },

  onLoad() {
    let count = wx.getStorageSync("muyu-count") || 0;
    let content = wx.getStorageSync("muyu-content") || "功德+1";
    this.setData({ count, content });
  },
});
